import django_filters
from rest_framework import filters
from django_filters.rest_framework import DjangoFilterBackend

from vouchers.models import *


class AliDiscountCouponFilter(django_filters.rest_framework.FilterSet):
    '''活动过滤'''

    coupon_status = django_filters.BaseInFilter(field_name='coupon_status', lookup_expr='in')
    coupon_channel = django_filters.BaseInFilter(field_name='coupon_channel', lookup_expr='in')
    coupon_way = django_filters.BaseInFilter(field_name='coupon_way', lookup_expr='in')
    distribution_platform_id = django_filters.BaseInFilter(field_name='distribution_platform_id', lookup_expr='in')
    publish_time_begin = django_filters.DateTimeFilter(field_name="publish_start_time__date", lookup_expr='gte')
    publish_time_end = django_filters.DateTimeFilter(field_name="publish_end_time__date", lookup_expr='lte')
    user_id = django_filters.BaseInFilter(field_name="user_id", lookup_expr='in')

    class Meta:
        model = AliDiscountCoupon
        fields = ('coupon_status', 'coupon_channel', 'coupon_way', 'distribution_platform_id', 'publish_time_begin', 'publish_time_end', 'user_id')

class AliCouponKeguanFilter(django_filters.rest_framework.FilterSet):
    '''支付宝、美团、微信、商家券-客管数据推送记录'''
    push_status = django_filters.BaseInFilter(field_name='push_status', lookup_expr='in')
    activity_id = django_filters.BaseInFilter(field_name='alidiscountcouponinfo_id', lookup_expr='in')
    push_time_begin = django_filters.DateTimeFilter(field_name="push_time__date", lookup_expr='gte')
    push_time_end = django_filters.DateTimeFilter(field_name="push_time__date", lookup_expr='lte')

    class Meta:
        model = AliDiscountCouponInfoKeguan
        fields = ('push_status', 'activity_id', 'push_time_begin', 'push_time_end')



class AliDiscountCouponLevelFilter(django_filters.rest_framework.FilterSet):
    '''活动过滤'''

    activity_id = django_filters.BaseInFilter(field_name='activity_id', lookup_expr='in')

    class Meta:
        model = AliDiscountCouponLevel
        fields = ('activity_id', )


class AliDiscountCouponMerchantTableHistoryFilter(django_filters.rest_framework.FilterSet):

    add_type = django_filters.BaseInFilter(field_name='add_type', lookup_expr='in')
    data_type = django_filters.BaseInFilter(field_name='data_type', lookup_expr='in')
    table_type = django_filters.BaseInFilter(field_name='table_type', lookup_expr='in')
    add_state = django_filters.BaseInFilter(field_name='add_state', lookup_expr='in')

    class Meta:
        model = AliDiscountCouponMerchantTableHistory
        fields = ('add_type', 'data_type', 'table_type', 'add_state')


class AliDiscountCouponMerchantTableFilter(django_filters.rest_framework.FilterSet):

    is_white = django_filters.BaseInFilter(field_name='is_white', lookup_expr='in')
    is_black = django_filters.BaseInFilter(field_name='is_black', lookup_expr='in')

    class Meta:
        model = AliDiscountCouponMerchantTable
        fields = ('is_white', 'is_black')


class AliDiscountCouponGoodsAvailableFilter(django_filters.rest_framework.FilterSet):

    goods_id = django_filters.BaseInFilter(field_name='goods_id', lookup_expr='in')
    alidiscountcoupon_id = django_filters.BaseInFilter(field_name='alidiscountcoupon_id', lookup_expr='in')

    class Meta:
        model = AliDiscountCouponGoodsAvailable
        fields = ('alidiscountcoupon_id', )


class AliDiscountCouponSyncWYHRecordFilter(django_filters.rest_framework.FilterSet):
    '''添加用户申请单过滤'''

    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')
    sync_status = django_filters.BaseInFilter(field_name='sync_status', lookup_expr='in')

    class Meta:
        model = AliDiscountCouponSyncWYHRecord
        fields = ('sync_status', 'create_time_begin', 'create_time_end')


class CustomizeActivityFlipCARDSFilter(django_filters.rest_framework.FilterSet):

    open_status = django_filters.BaseInFilter(field_name='open_status', lookup_expr='in')
    customizeactivity_id = django_filters.BaseInFilter(field_name='customizeactivity_id', lookup_expr='in')
    received_time_begin = django_filters.DateTimeFilter(field_name="received_time__date", lookup_expr='gte')
    received_time_end = django_filters.DateTimeFilter(field_name="received_time__date", lookup_expr='lte')

    class Meta:
        model = CustomizeActivityFlipCARDS
        fields = ('open_status', 'customizeactivity_id', 'received_time_begin', 'received_time_end')


class UpdateStockUsableMerchantFilter(django_filters.rest_framework.FilterSet):
    '''添加用户申请单过滤'''

    alidiscountcoupon_id = django_filters.BaseInFilter(field_name='alidiscountcoupon_id', lookup_expr='in')
    apply_state = django_filters.BaseInFilter(field_name='apply_state', lookup_expr='in')

    class Meta:
        model = UpdateStockUsableMerchant
        fields = ('alidiscountcoupon_id', 'apply_state')


class AliDiscountCouponInfoFilter(django_filters.rest_framework.FilterSet):
    '''领取明细过滤'''

    alidiscountcoupon_level_id = django_filters.BaseInFilter(field_name='alidiscountcoupon_level_id', lookup_expr='in')
    status = django_filters.BaseInFilter(field_name='status', lookup_expr='in')
    level_id = django_filters.BaseInFilter(field_name='level_id', lookup_expr='in')
    activity_id = django_filters.BaseInFilter(field_name='alidiscountcoupon_id', lookup_expr='in')
    coupon_channel = django_filters.BaseInFilter(field_name='coupon_channel', lookup_expr='in')

    class Meta:
        model = AliDiscountCouponInfo
        fields = ('alidiscountcoupon_level_id', 'status', 'level_id', 'activity_id', 'coupon_channel')


class AliDiscountCouponMerchantFilter(django_filters.rest_framework.FilterSet):

    alidiscountcoupon_id = django_filters.BaseInFilter(field_name='alidiscountcoupon_id', lookup_expr='in')

    class Meta:
        model = AliDiscountCouponMerchant
        fields = ('alidiscountcoupon_id',)


class CustomizeActivityFilter(django_filters.rest_framework.FilterSet):

    activity_status = django_filters.BaseInFilter(field_name='activity_status', lookup_expr='in')
    activity_type = django_filters.BaseInFilter(field_name='activity_type', lookup_expr='in')

    class Meta:
        model = CustomizeActivity
        fields = ('activity_status', 'activity_type')


class CustomizeActivityLevelFilter(django_filters.rest_framework.FilterSet):
    '''活动过滤'''

    customizeactivity_id = django_filters.BaseInFilter(field_name='customizeactivity_id', lookup_expr='in')

    class Meta:
        model = CustomizeActivityLevel
        fields = ('customizeactivity_id', )